package com.im.app.processor;

import com.im.app.model.ChatLogs;
import com.im.app.model.Conversations;
import com.im.app.model.User;
import com.im.app.service.ChatLogsService;
import com.im.app.service.ConversationsService;
import com.im.app.service.IUserService;
import com.im.app.utils.uuid.IdUtils;
import org.jim.core.ImChannelContext;
import org.jim.core.packets.*;
import org.jim.core.utils.JsonKit;
import org.jim.server.JimServerAPI;
import org.jim.server.processor.chat.BaseAsyncChatMessageProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.*;

@Component("chatMessageProcessor")
public class ChatMessageProcessor extends BaseAsyncChatMessageProcessor {

    private static Logger logger = LoggerFactory.getLogger(ChatMessageProcessor.class);
    public static ChatMessageProcessor cmp;

    @Autowired
    private ChatLogsService chatLogsService;

    @PostConstruct
    public void init() {
        cmp = this;
        cmp.chatLogsService = this.chatLogsService;
    }

    @Override
    public void doProcess(ChatBody chatBody, ImChannelContext imChannelContext){
        ChatLogs chatLogs = ChatLogs.bodyToLog(chatBody);
        cmp.chatLogsService.insert(chatLogs);
    }

}
